#include "qfuncx.h"
#include "ui_qfuncx.h"

QFuncX::QFuncX(QWidget *parent) :
    QWidget(parent),
	ui(new Ui::QFuncX)
{
    ui->setupUi(this);

//    //add highlight
//    new JSHighlighter(ui->plainTextEdit->document());
}

QFuncX::~QFuncX()
{
    delete ui;
}

void QFuncX::getFunc(CFuncX *&f, Piped &p)
{
	QScriptEngine engine;
	engine.evaluate(ui->plainTextEdit->toPlainText());
	QScriptValue A = engine.globalObject().property("A");
	vector<double> l;
	qScriptValueToSequence(A, l);
	int n = l.size();
	p.resize(n/2);
	for (int i = 0; i < n/2; ++i)
	{
		p[i].a = l[2*i];
		p[i].b = l[2*i + 1];
	}

	f = new CJSFuncX(ui->plainTextEdit->toPlainText());

//	p.resize(2);
//	p[1].a = p[0].a = ui->lineEdit_a->text().toDouble();
//	p[1].b = p[0].b = ui->lineEdit_b->text().toDouble();
}
